package jwt

import (
	"time"

	"github.com/golang-jwt/jwt/v4"
)

type Claims struct {
	UserId uint64 `json:"user_id"`
	jwt.StandardClaims
}

func GenerateToken(userId uint64, secretKey []byte) (string, error) {
	expirationTime := time.Now().Add(24 * time.Hour) // Token有效期为24小时

	claims := Claims{
		UserId: userId,
		StandardClaims: jwt.StandardClaims{
			ExpiresAt: expirationTime.Unix(),
		},
	}

	token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)

	return token.SignedString(secretKey)
}
